package com.linkage.usercenter.config;

import feign.Feign;
import okhttp3.ConnectionPool;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;


/* *
 * @describe:  类型描述 FeignOkHttp配置类
 * @author shaofeng.cheng
 * @title
 * @date 2020/5/10 14:01
 * @param
 * @return
 * @version: V1.0
 */
@Configuration
@ConditionalOnClass(Feign.class)
@AutoConfigureBefore(FeignAutoConfiguration.class)
public class FeignOkHttpConfig {
	
	/* *
	 * @describe:  类型描述 FeignOkHttp初始化参数配置
	 * @author shaofeng.cheng
	 * @title
	 * @date 2020/5/10 14:02
	 * @param
	 * @return
	 * @version: V1.0
	 */
	@Bean
	public okhttp3.OkHttpClient okHttpClient(){
		return new okhttp3.OkHttpClient.Builder()
				//设置连接超时时间
				.connectTimeout(120, TimeUnit.SECONDS)
				//设置读取超时
				.readTimeout(120, TimeUnit.SECONDS)
				//设置写入超时
				.writeTimeout(120, TimeUnit.SECONDS)
				//是否自动重连
				.retryOnConnectionFailure(true)
				.connectionPool(new ConnectionPool()).build();
				
	}
}
